<?php

use yii\helpers\Html;
use yii\grid\GridView;
use kartik\file\FileInput;


$this->title = '会员管理';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="member-index">

    <h2 class="page-header"><?= Html::encode($this->title) ?>
        <div class="pull-right" style="display: inline-block;">
            <?= Html::a('创建人员', ['create'], ['class' => 'btn btn-success']) ?>
            <div style="display: inline-block;">
            <?php echo FileInput::widget([
                  'language' => 'zh',
                  'name' => 'excel',
                  'id' => 'file-upload',
                  'pluginOptions' => [
                      'uploadUrl' => "/cruise/member/import",
                      'uploadExtraData' => [
                          '_csrf' => Yii::$app->getRequest()->getCsrfToken(),
                      ],
                      'showPreview' => false,
                      'showCaption' => false,
                      'showRemove' => false,
                      'showUpload' => false,
                      'uploadAsync'=> true,
                      'maxFileCount' => 1,
                      'browseClass' => 'btn btn-warning',
                      'browseIcon' => '',
                      'browseLabel' => '上传人员',
                      'fileTypeSettings' => [],
                  ],
                  'options' => ['accept' => '', 'multiple'=>false],
                  ]);?>
        </div>
        <a class="btn btn-primary" href="/download/template3.xlsx" >下载导入人员模板</a>  
    </h2>

    <p>
        <?php echo $this->render('_search', ['model' => $searchModel]); ?>
    </p>

    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        //'filterModel' => $searchModel,
        'layout'  =>  "{items}\n{pager}",
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],

            //'id',
            'phone',
            //'passwd',
            'name',
            //'group_num',
            //'role',
            [
                'attribute' => 'role',
                'filter' =>  Yii::$app->params['role'],
                'value' => function ($model) {
                    return Yii::$app->params['role'][$model->role];
                },
                'format' => 'raw',
            ],
            [
                'attribute' => 'group_num',
                'value' => function($model){
                    $v = '';
                    if($model->group_num){
                        $v = json_decode($model->group_num);
                        if(is_array($v)){
                           $v = implode(",",$v);
                        }
                    }
                    return  $v;
                },
                'format' => 'raw',
            ],
            //'login_time',
            //'desc',
            //'status',
            [
                'attribute' => 'status',
                'filter' =>  Yii::$app->params['status'],
                'value' => function ($model) {
                    return Yii::$app->params['status'][$model->status];
                },
                'format' => 'raw',
            ],
            //'user_id',
            //'created_at',
            //'updated_at',

            ['class' => 'yii\grid\ActionColumn'],
        ],
    ]); ?>
</div>
<?=  yii\web\View::registerJsFile("/js/layer/layer.js",['depends' => 'app\assets\AppAsset']) ?>

<?php app\components\JsBlock::begin() ?>
<script type="text/javascript">

  $('#file-upload').on('filebatchselected', function(event, files) {
      $(this).fileinput("upload");
  });

  $('#file-upload').on('fileuploaded', function(event, data, previewId, index) {
      var response = data.response;
      if(response.code == 'error'){
          layer.msg(response.message,{time: 5000},function(){});
          setTimeout("window.location.reload()",5000);
          return false;
      }else if(response.code == 'ok'){
          layer.msg(response.message);
          window.location.reload();
          return false;
      }
  });


</script>
<?php app\components\JsBlock::end() ?>  